/*
 * Copyright (C) 2009 Kristopher T Babic
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses>.
 */

package edu.idp.client.anim;

import java.awt.*;

public class SinePath extends AnimationPath {

    private static final double _defaultAmplitude = 10;
    private static final double _defaultFrequency = 0.25;
    private static final double _defaultDeltaAngle = Math.toRadians(1.0);

    private double deltaAngle;
    private double amplitude;
    private double frequency;

    public SinePath() {
        super();
        init(_defaultAmplitude, _defaultFrequency, _defaultDeltaAngle);
    }

    public SinePath(Point origin) {
        super(origin);
        init(_defaultAmplitude, _defaultFrequency, _defaultDeltaAngle);
    }

    public SinePath(Point origin, double amp, double freq) {
        super(origin);
        init(amp, freq, _defaultDeltaAngle);
    }

    public SinePath(Point origin, double amp, double freq, double angle) {
        super(origin);
        init(amp, freq, angle);
    }

    private void init(double amp, double freq, double angle) {
        setAmplitude(amp);
        setFrequency(freq);
        setDeltaAngle(angle);
    }

    public void setDeltaAngle(double angle) {
        this.deltaAngle = Math.toRadians(angle);
    }

    public void setAmplitude(double amp) {
        this.amplitude = amp;
    }

    public void setFrequency(double freq) {
        this.frequency = freq;
    }

    public double getFrequency() {
        return this.frequency;
    }

    public double getAmplitude() {
        return this.amplitude;
    }

    public double getDeltaAngle() {
        return Math.toDegrees(this.deltaAngle);
    }

    private double getDeltaAngleRadians() {
        return this.deltaAngle;
    }

    public String toString() {
        return "Sine Path -\nAmplitude: " + getAmplitude() + "\nFrequenchy: " + getFrequency() + "\nDelta Angle: " + getDeltaAngle();
    }

    public Point getLocation() {
        double angle = getDeltaAngleRadians() * (double) getCycles();

        double a = getAmplitude();
        double f = getFrequency();

        Point loc = getStartLocation();
//System.out.print(loc+"->");
        int x = (int) Math.toDegrees(angle) + loc.x;//(f * angle);//(a * Math.cos (f * angle) + (double)loc.x);
        int y = (int) (a * Math.sin(f * angle) + (double) loc.y);
//System.out.println("("+x+","+y+")");
        return getReflectedLocation(x, y);
    }

    public void setLocation(Point loc) {
        setStartLocation(loc);
        setStartTime();
    }

}